package dao;

import domain.Member;
import domain.Orders;
import domain.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface IOrderDao {

    @Select("select * from orders")
    @Results({
            @Result(id = true, column = "id", property = "id"),//true表示是否为主键
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "peopleCount", property = "peopleCount"),
            @Result(column = "payType", property = "payType"),
            @Result(column = "orderDesc", property = "orderDesc"),
            @Result(column = "productId",property = "product",one = @One(select = "dao.IProductDao.findById"))
    })
    List<Orders> findAll() throws Exception;

    @Select("select * from orders where id = #{orderId}")
    @Results({
            @Result(id = true, column = "id", property = "id"),//true表示是否为主键
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "peopleCount", property = "peopleCount"),
            @Result(column = "payType", property = "payType"),
            @Result(column = "orderDesc", property = "orderDesc"),
            @Result(column = "productId",property = "product",javaType = Product.class,one = @One(select = "dao.IProductDao.findById")),
            @Result(column = "memberId",property = "member",javaType = Member.class,one = @One(select = "dao.IMemberDao.findById")),
            @Result(column = "id",property = "travellers",javaType =List.class,many = @Many(select = "dao.ITraveller.findById"))
    })
    Orders findById(int orderId) throws Exception;
}
